Dynomotion

Group: DynoMotion Message: 12277 From: shannonjdavenport Date: 9/18/2015
Subject: Opening Gcode files

Hi Tom,

I've got an application written in VB6 that provides our machine operators with a graphical Gcode interface which does some post processing for stops starts etc.  It works fine and the only issue is that the operator needs to load the Gcode file in both KmotionCNC and my app.  It would be nice if they could load in one app or the other and then force the other to load the same file.  So, is there any way I can either detect what is being loaded into KmotionCNC or tell KmotionCNC what to load?  

Thanks, Shannon

 

Group: DynoMotion Message: 12304 From: Tom Kerekes Date: 9/23/2015
Subject: Re: Opening Gcode files
Hi Shannon,

Here is a patched KMotionCNC compatible with Release V4.33q that includes three new KMotionCNC "automation" commands:

    ON_COMMAND(ID_ReloadGCodeFile, OnReloadGCodeFile)
    ON_COMMAND(ID_OpenGCodeFile, OnOpenGCodeFile)
    ON_WM_COPYDATA()

The Binaries and changed source files are here:


Here is the related code added to KMotionCNC:

void CKMotionCNCDlg::OnReloadGCodeFile()
{
    LoadFile(m_Thread,true);
    CurrentDirectory = ExtractDirectory(FileNames[m_Thread]);
}

void CKMotionCNCDlg::OnOpenGCodeFile()
{
    FileNames[m_Thread] = InterprocessString;
    LoadFile(m_Thread,true);
    CurrentDirectory = ExtractDirectory(FileNames[m_Thread]);
}

BOOL CKMotionCNCDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
    InterprocessString = (LPCTSTR)pCopyDataStruct->lpData;
    return TRUE;
}



We added an example Button in the SimpleFormsCS C# example to demonstrate the functionality.  See the top right button:

Inline image

It loads the fixed file "Dynomotion.ngc" from the GCode Programs directory.

The related code from Form1.cs is:

        private void TestOpenKMotionCNC_click(object sender, EventArgs e)
        {
            String message = MainPath + "\\GCode Programs\\Dynomotion.ngc";
            COPYDATASTRUCT cds;
            cds.dwData = 0;
            cds.lpData = (int)Marshal.StringToHGlobalAnsi(message);
            cds.cbData = message.Length+1;

            IntPtr KMotionCNCWindow = FindWindow("KMotionCNC", null);
            SendMessage(KMotionCNCWindow, (int)WM_COPYDATA, 0, ref cds);
            Marshal.FreeHGlobal((IntPtr)cds.lpData);

            uint WM_COMMAND = 0x0111;
            int ID_OpenGCodeFile = 33018;
            SendMessage(KMotionCNCWindow, (int)WM_COMMAND, ID_OpenGCodeFile, 0);
        }


Let us know if you have any issues.

Regards
TK



Group: DynoMotion Message: 12307 From: Shannon Davenport Date: 9/24/2015
Subject: Re: Opening Gcode files [1 Attachment]
Hi Tom,
Sorry for my lack of understanding here; but how do I implement this new functionality?
I downloaded the files and am running the new KMotionCNC.  I looked at the source code and it looks like the just opened file name should be here: C:\KMotion433q\KMotion\Data\GFilescnc.txt.  But I don't see it until KmotionCNC is closed.
Thanks, Shannon

On Wed, Sep 23, 2015 at 6:57 PM, Tom Kerekes tk@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 
[Attachment(s) from Tom Kerekes included below]

Hi Shannon,

Here is a patched KMotionCNC compatible with Release V4.33q that includes three new KMotionCNC "automation" commands:

    ON_COMMAND(ID_ReloadGCodeFile, OnReloadGCodeFile)
    ON_COMMAND(ID_OpenGCodeFile, OnOpenGCodeFile)
    ON_WM_COPYDATA()

The Binaries and changed source files are here:


Here is the related code added to KMotionCNC:

void CKMotionCNCDlg::OnReloadGCodeFile()
{
    LoadFile(m_Thread,true);
    CurrentDirectory = ExtractDirectory(FileNames[m_Thread]);
}

void CKMotionCNCDlg::OnOpenGCodeFile()
{
    FileNames[m_Thread] = InterprocessString;
    LoadFile(m_Thread,true);
    CurrentDirectory = ExtractDirectory(FileNames[m_Thread]);
}

BOOL CKMotionCNCDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
    InterprocessString = (LPCTSTR)pCopyDataStruct->lpData;
    return TRUE;
}



We added an example Button in the SimpleFormsCS C# example to demonstrate the functionality.  See the top right button:

Inline image

It loads the fixed file "Dynomotion.ngc" from the GCode Programs directory.

The related code from Form1.cs is:

        private void TestOpenKMotionCNC_click(object sender, EventArgs e)
        {
            String message = MainPath + "\\GCode Programs\\Dynomotion.ngc";
            COPYDATASTRUCT cds;
            cds.dwData = 0;
            cds.lpData = (int)Marshal.StringToHGlobalAnsi(message);
            cds.cbData = message.Length+1;

            IntPtr KMotionCNCWindow = FindWindow("KMotionCNC", null);
            SendMessage(KMotionCNCWindow, (int)WM_COPYDATA, 0, ref cds);
            Marshal.FreeHGlobal((IntPtr)cds.lpData);

            uint WM_COMMAND = 0x0111;
            int ID_OpenGCodeFile = 33018;
            SendMessage(KMotionCNCWindow, (int)WM_COMMAND, ID_OpenGCodeFile, 0);
        }


Let us know if you have any issues.

Regards
TK



Group: DynoMotion Message: 12308 From: Tom Kerekes Date: 9/24/2015
Subject: Re: Opening Gcode files
Hi Shannon,

The new functionality should allow your VB application to open any GCode file in KMotionCNC as if the Operator did a File Open.   I thought that's what you were asking to do?

Were you able to push the button in the SimpleFormsCS example and see KMotionCNC open the GCode File Dynomotion.ngc?

From your VB program you would need to find the KMotionCNC main window, send the file name to open, then the open file message in a similar manner as shown in the SimpleFormsCS C# example does.

HTH
Regards
TK

On Sep 24, 2015, at 6:30 AM, Shannon Davenport sdavenport.roa@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:

 

Hi Tom,
Sorry for my lack of understanding here; but how do I implement this new functionality?
I downloaded the files and am running the new KMotionCNC.  I looked at the source code and it looks like the just opened file name should be here: C:\KMotion433q\KMotion\Data\GFilescnc.txt.  But I don't see it until KmotionCNC is closed.
Thanks, Shannon

On Wed, Sep 23, 2015 at 6:57 PM, Tom Kerekes tk@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 
[Attachment(s) from Tom Kerekes included below]

Hi Shannon,

Here is a patched KMotionCNC compatible with Release V4.33q that includes three new KMotionCNC "automation" commands:

    ON_COMMAND(ID_ReloadGCodeFile, OnReloadGCodeFile)
    ON_COMMAND(ID_OpenGCodeFile, OnOpenGCodeFile)
    ON_WM_COPYDATA()

The Binaries and changed source files are here:


Here is the related code added to KMotionCNC:

void CKMotionCNCDlg::OnReloadGCodeFile()
{
    LoadFile(m_Thread,true);
    CurrentDirectory = ExtractDirectory(FileNames[m_Thread]);
}

void CKMotionCNCDlg::OnOpenGCodeFile()
{
    FileNames[m_Thread] = InterprocessString;
    LoadFile(m_Thread,true);
    CurrentDirectory = ExtractDirectory(FileNames[m_Thread]);
}

BOOL CKMotionCNCDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
    InterprocessString = (LPCTSTR)pCopyDataStruct->lpData;
    return TRUE;
}



We added an example Button in the SimpleFormsCS C# example to demonstrate the functionality.  See the top right button:

Inline image

It loads the fixed file "Dynomotion.ngc" from the GCode Programs directory.

The related code from Form1.cs is:

        private void TestOpenKMotionCNC_click(object sender, EventArgs e)
        {
            String message = MainPath + "\\GCode Programs\\Dynomotion.ngc";
            COPYDATASTRUCT cds;
            cds.dwData = 0;
            cds.lpData = (int)Marshal.StringToHGlobalAnsi(message);
            cds.cbData = message.Length+1;

            IntPtr KMotionCNCWindow = FindWindow("KMotionCNC", null);
            SendMessage(KMotionCNCWindow, (int)WM_COPYDATA, 0, ref cds);
            Marshal.FreeHGlobal((IntPtr)cds.lpData);

            uint WM_COMMAND = 0x0111;
            int ID_OpenGCodeFile = 33018;
            SendMessage(KMotionCNCWindow, (int)WM_COMMAND, ID_OpenGCodeFile, 0);
        }


Let us know if you have any issues.

Regards
TK



Group: DynoMotion Message: 12309 From: Shannon Davenport Date: 9/24/2015
Subject: Re: Opening Gcode files
That is what I wanted.  just wasn't sure which method you would employ.  From the VB side or from the kmotion side.  And no I was not able to get the SimpleFormsCS C# example to work.  I would need C# right?   However, I am able to get a handle to KMotionCNC and send it a string which replaces whatever is in the title bar.  After that I'm not sure what to do.

On Thu, Sep 24, 2015 at 9:53 AM, Tom Kerekes tk@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

Hi Shannon,

The new functionality should allow your VB application to open any GCode file in KMotionCNC as if the Operator did a File Open.   I thought that's what you were asking to do?

Were you able to push the button in the SimpleFormsCS example and see KMotionCNC open the GCode File Dynomotion.ngc?

From your VB program you would need to find the KMotionCNC main window, send the file name to open, then the open file message in a similar manner as shown in the SimpleFormsCS C# example does.

HTH
Regards
TK

On Sep 24, 2015, at 6:30 AM, Shannon Davenport sdavenport.roa@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:

 

Hi Tom,
Sorry for my lack of understanding here; but how do I implement this new functionality?
I downloaded the files and am running the new KMotionCNC.  I looked at the source code and it looks like the just opened file name should be here: C:\KMotion433q\KMotion\Data\GFilescnc.txt.  But I don't see it until KmotionCNC is closed.
Thanks, Shannon

On Wed, Sep 23, 2015 at 6:57 PM, Tom Kerekes tk@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 
[Attachment(s) from Tom Kerekes included below]

Hi Shannon,

Here is a patched KMotionCNC compatible with Release V4.33q that includes three new KMotionCNC "automation" commands:

    ON_COMMAND(ID_ReloadGCodeFile, OnReloadGCodeFile)
    ON_COMMAND(ID_OpenGCodeFile, OnOpenGCodeFile)
    ON_WM_COPYDATA()

The Binaries and changed source files are here:


Here is the related code added to KMotionCNC:

void CKMotionCNCDlg::OnReloadGCodeFile()
{
    LoadFile(m_Thread,true);
    CurrentDirectory = ExtractDirectory(FileNames[m_Thread]);
}

void CKMotionCNCDlg::OnOpenGCodeFile()
{
    FileNames[m_Thread] = InterprocessString;
    LoadFile(m_Thread,true);
    CurrentDirectory = ExtractDirectory(FileNames[m_Thread]);
}

BOOL CKMotionCNCDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
    InterprocessString = (LPCTSTR)pCopyDataStruct->lpData;
    return TRUE;
}



We added an example Button in the SimpleFormsCS C# example to demonstrate the functionality.  See the top right button:

Inline image

It loads the fixed file "Dynomotion.ngc" from the GCode Programs directory.

The related code from Form1.cs is:

        private void TestOpenKMotionCNC_click(object sender, EventArgs e)
        {
            String message = MainPath + "\\GCode Programs\\Dynomotion.ngc";
            COPYDATASTRUCT cds;
            cds.dwData = 0;
            cds.lpData = (int)Marshal.StringToHGlobalAnsi(message);
            cds.cbData = message.Length+1;

            IntPtr KMotionCNCWindow = FindWindow("KMotionCNC", null);
            SendMessage(KMotionCNCWindow, (int)WM_COPYDATA, 0, ref cds);
            Marshal.FreeHGlobal((IntPtr)cds.lpData);

            uint WM_COMMAND = 0x0111;
            int ID_OpenGCodeFile = 33018;
            SendMessage(KMotionCNCWindow, (int)WM_COMMAND, ID_OpenGCodeFile, 0);
        }


Let us know if you have any issues.

Regards
TK



Group: DynoMotion Message: 12310 From: Tom Kerekes Date: 9/24/2015
Subject: Re: Opening Gcode files
Hi Shannon,

Yes SimpleFormsCS is a C# program.  But I included the executable so you should be able to just run it.  I believe it requires .NET 3.5 loaded on your Windows system to run.

But regardless it seems like you are able to now send Windows Messages to KMotionCNC which is half the battle.

Sending a WM_COMMAND command message with ID 33018 will cause KMotionCNC to open a GCode File.  But first it has to be told what file to open.  Unfortunately there is no way to include and variable amount of data (like a filename string) in a simple windows message.  And the two different applications are in two different virtual memory spaces so a pointer reference can't be passed either.  So the special WM_COPYDATA method/message is used first to copy the string from your application over to KMotionCNC.  Please look at how that is accomplished in theSimpleFormsCS and see if you can figure out how to do it in VB6.

Regards
TK




Group: DynoMotion Message: 12311 From: Shannon Davenport Date: 9/25/2015
Subject: Re: Opening Gcode files
Hi Tom,
Not many people/companies would be willing to cater to the whims of an old programmer who just won't give up on his old VB6.  I did as you suggested and everything is working perfectly.  Thanks again for bailing me out and for your excellent support. 
Shannon


'***The required code to open a file in KMotionCNC from VB6*** 

If CD1.FileName <> "" Then
    GCodeFileName = CD1.FileName
    Draw_G_Code GCodeFileName
    Dim lhWndP As Long
    Dim cds As COPYDATASTRUCT
    Dim buf(1 To 255) As Byte
    Dim i As Long
    If GetHandleFromPartialCaption(lhWndP, "KMotionCNC") = True Then
        CopyMemory buf(1), ByVal CD1.FileName, Len(CD1.FileName)
        cds.dwData = 0
        cds.cbData = Len(CD1.FileName) + 1
        cds.lpData = VarPtr(buf(1))
        SendMessage lhWndP, WM_COPYDATA, Me.hwnd, cds
        SendMessage lhWndP, WM_COMMAND, 33018, 0
    End If
    Resize
    Me.Caption = "Grapical Gcode Interface - " & CD1.FileTitle
End if

Public Type COPYDATASTRUCT
      dwData As Long
      cbData As Long
      lpData As Long
End Type

Public Function GetHandleFromPartialCaption(ByRef lWnd As Long, ByVal sCaption As String) As Boolean
    Dim lhWndP As Long
    Dim sStr As String
    GetHandleFromPartialCaption = False
    lhWndP = FindWindow(vbNullString, vbNullString) 'PARENT WINDOW
    Do While lhWndP <> 0
        sStr = String(GetWindowTextLength(lhWndP) + 1, Chr$(0))
        GetWindowText lhWndP, sStr, Len(sStr)
        sStr = Left$(sStr, Len(sStr) - 1)
        If InStr(1, sStr, sCaption) > 0 Then
            GetHandleFromPartialCaption = True
            lWnd = lhWndP
            Exit Do
        End If
        lhWndP = GetWindow(lhWndP, GW_HWNDNEXT)
    Loop

End Function


On Thu, Sep 24, 2015 at 9:53 AM, Tom Kerekes tk@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

Hi Shannon,

The new functionality should allow your VB application to open any GCode file in KMotionCNC as if the Operator did a File Open.   I thought that's what you were asking to do?

Were you able to push the button in the SimpleFormsCS example and see KMotionCNC open the GCode File Dynomotion.ngc?

From your VB program you would need to find the KMotionCNC main window, send the file name to open, then the open file message in a similar manner as shown in the SimpleFormsCS C# example does.

HTH
Regards
TK

On Sep 24, 2015, at 6:30 AM, Shannon Davenport sdavenport.roa@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:

 

Hi Tom,
Sorry for my lack of understanding here; but how do I implement this new functionality?
I downloaded the files and am running the new KMotionCNC.  I looked at the source code and it looks like the just opened file name should be here: C:\KMotion433q\KMotion\Data\GFilescnc.txt.  But I don't see it until KmotionCNC is closed.
Thanks, Shannon

On Wed, Sep 23, 2015 at 6:57 PM, Tom Kerekes tk@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 
[Attachment(s) from Tom Kerekes included below]

Hi Shannon,

Here is a patched KMotionCNC compatible with Release V4.33q that includes three new KMotionCNC "automation" commands:

    ON_COMMAND(ID_ReloadGCodeFile, OnReloadGCodeFile)
    ON_COMMAND(ID_OpenGCodeFile, OnOpenGCodeFile)
    ON_WM_COPYDATA()

The Binaries and changed source files are here:


Here is the related code added to KMotionCNC:

void CKMotionCNCDlg::OnReloadGCodeFile()
{
    LoadFile(m_Thread,true);
    CurrentDirectory = ExtractDirectory(FileNames[m_Thread]);
}

void CKMotionCNCDlg::OnOpenGCodeFile()
{
    FileNames[m_Thread] = InterprocessString;
    LoadFile(m_Thread,true);
    CurrentDirectory = ExtractDirectory(FileNames[m_Thread]);
}

BOOL CKMotionCNCDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
    InterprocessString = (LPCTSTR)pCopyDataStruct->lpData;
    return TRUE;
}



We added an example Button in the SimpleFormsCS C# example to demonstrate the functionality.  See the top right button:

Inline image

It loads the fixed file "Dynomotion.ngc" from the GCode Programs directory.

The related code from Form1.cs is:

        private void TestOpenKMotionCNC_click(object sender, EventArgs e)
        {
            String message = MainPath + "\\GCode Programs\\Dynomotion.ngc";
            COPYDATASTRUCT cds;
            cds.dwData = 0;
            cds.lpData = (int)Marshal.StringToHGlobalAnsi(message);
            cds.cbData = message.Length+1;

            IntPtr KMotionCNCWindow = FindWindow("KMotionCNC", null);
            SendMessage(KMotionCNCWindow, (int)WM_COPYDATA, 0, ref cds);
            Marshal.FreeHGlobal((IntPtr)cds.lpData);

            uint WM_COMMAND = 0x0111;
            int ID_OpenGCodeFile = 33018;
            SendMessage(KMotionCNCWindow, (int)WM_COMMAND, ID_OpenGCodeFile, 0);
        }


Let us know if you have any issues.

Regards
TK